import axios from 'axios'
// import { getItem, removeItem } from '@/utils/token'
import { Message } from 'element-ui'
import { createRouter } from '@/router'
const request = axios.create({
  baseURL: "http://localhost:8089/api",
})


// 请求拦截器
request.interceptors.request.use(function (config) {
  config.headers.Authorization = `Bearer ${sessionStorage.getItem("token")}`
  return config
})
// 响应拦截器
request.interceptors.response.use(function (config) {
  const { status, message } = config.data
  if (status == '500') {
    Message.error('登录已过期，请重新登录')
    sessionStorage.removeItem('token')
    createRouter.push('/login')
  } else if (status !== '200' && status !== '500') {
    Message.error(message)
  }
  return config
}, error => {
  return Message.error(error)
})
export default request
